package com.seeTools.next.controller.sys;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.seeTools.next.api.entity.sys.SysTenant;
import com.seeTools.next.common.core.PageQuery;
import com.seeTools.next.common.core.Result;
import com.seeTools.next.service.sys.ISysTenantService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 租户信息表 前端控制器
 * </p>
 *
 * @author FallenDust
 * @since 2023-05-11
 */
@RestController
@RequestMapping("/sysTenant")
public class SysTenantController {

    @Resource
    private ISysTenantService service;

    /**
     * 分页查询
     *
     * @param pageQuery 查询条件
     * @return 结果
     */
    @SaCheckPermission("tenant.list")
    @PostMapping("/page")
    public Result<Page<SysTenant>> page(@RequestBody PageQuery<SysTenant> pageQuery) {
        Page<SysTenant> pageInfo = service.pageInfo(pageQuery);
        return Result.state(pageInfo);
    }

    /**
     * 新增
     *
     * @param entity 实体
     * @return Result
     */
    @SaCheckPermission("tenant.add")
    @PostMapping("/add")
    public Result<Void> add(@RequestBody SysTenant entity) {
        return Result.state(service.save(entity));
    }


    /**
     * 更新
     *
     * @param entity 实体
     * @return Result
     */
    @SaCheckPermission("tenant.edit")
    @PostMapping("/update")
    public Result<Void> update(@RequestBody SysTenant entity) {
        return Result.state(service.updateById(entity));
    }

    /**
     * 删除
     *
     * @param entity 实体
     * @return Result
     */
    @SaCheckPermission("tenant.del")
    @PostMapping("/delete")
    public Result<Void> delete(@RequestBody SysTenant entity) {
        return Result.state(service.removeById(entity));
    }


    /**
     * 详情
     *
     * @param id id
     * @return Result
     */
    @GetMapping("/info/{id}")
    public Result<SysTenant> info(@PathVariable("id") Long id) {
        return Result.state(service.getById(id));
    }
}
